﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace FrameworkXNA.Scenes
{
    class Level1 : SceneBase
    {
        Object2D erica;
        Object2D fadeout;

        bool starting;
        bool fading;

        public override void start()
        {
            starting = true;

            erica = new Object2D(Game1.instance.Content.Load<Texture2D>("erica")) { x = Game1.instance.graphics.PreferredBackBufferWidth / 2, y = Game1.instance.graphics.PreferredBackBufferHeight / 2 };

            fadeout = new Object2D(Game1.instance.Content.Load<Texture2D>("blackpixel")) { alpha = 1 };
            fadeout.setHeight(Game1.instance.graphics.PreferredBackBufferHeight);
            fadeout.setWidth(Game1.instance.graphics.PreferredBackBufferWidth);

            base.start();
        }

        public override void draw(SpriteBatch spriteBatch)
        {
            erica.Draw(spriteBatch);
            fadeout.Draw(spriteBatch);
            base.draw(spriteBatch);
        }

        public override void update(GameTime gameTime)
        {
            if (starting)
            {
                fadeout.alpha -= 0.01f;

                if (fadeout.alpha <= 0)
                {
                    fadeout.alpha = 0;
                    starting = false;
                }
            }

            if (Controller.keyPressed(Keys.Escape))
            {
                fading = true;
            }

            if (fading)
            {
                fadeout.alpha += 0.01f;

                if (fadeout.alpha > 1)
                {
                    SceneManager.setScene(new Menu());
                }
            }

            characterControl();

            base.update(gameTime);
        }

        private void characterControl()
        {
            if (Controller.keyDown(Keys.Right))
            {
                erica.x += 5;
            }
            if (Controller.keyDown(Keys.Left))
            {
                erica.x -= 5;
            }
            if (Controller.keyDown(Keys.Up))
            {
                erica.y -= 5;
            }
            if (Controller.keyDown(Keys.Down))
            {
                erica.y += 5;
            }
        }
    }
}
